package personnel.department.pages;

import java.util.List;


import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.widgets.Composite;

import personnel.department.dao.entity.Employee;
import personnel.department.dao.entity.StructualSubdivision;

public class SearchPersonalPage extends AbstractPage<Employee> {

	
	
	public SearchPersonalPage(String pageName) {
		super(pageName);
	}

	@Override
	protected List<Employee> getModelProvider() {
		return ModelProviderFactory.employeeModel();
	}

	@Override
	protected void createColumns(Composite parent, TableViewer viewer) {
		 String[] titles = { "Фамилия", "Имя", "Должность", "Структурное подраздаление" };
		    int[] bounds = { 120, 100, 180, 170 };

		    TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);
		    col.setLabelProvider(new ColumnLabelProvider() {
		      @Override
		      public String getText(Object element) {
		       Employee e = (Employee) element;
		        return e.getSurname();
		      }
		    });

		    col = createTableViewerColumn(titles[1], bounds[1], 1);
		    col.setLabelProvider(new ColumnLabelProvider() {
		      @Override
		      public String getText(Object element) {
			       Employee e = (Employee) element;
			        return e.getFirstName();
		      }
		    });

		    col = createTableViewerColumn(titles[2], bounds[2], 2);
		    col.setLabelProvider(new ColumnLabelProvider() {
		      @Override
		      public String getText(Object element) {
			       Employee e = (Employee) element;
			        return e.getType().getPost();
		      }
		    });

		    col = createTableViewerColumn(titles[3], bounds[3], 3);
		    col.setLabelProvider(new ColumnLabelProvider() {
		      @Override
		      public String getText(Object element) {
			       Employee e = (Employee) element;
			        StructualSubdivision subdivision = e.getSubdivision();
			        return subdivision != null ? subdivision.getSubdivisionName() : null;
		      }
		    });

		  }
	


}
